package com.rockcent.wechat.controller;

import com.rockcent.common.common.JsonResult;
import com.rockcent.common.common.PageResult;
import com.rockcent.common.common.RestDoing;
import com.rockcent.common.controller.BaseController;
import com.rockcent.common.domain.enumclass.Whether;
import com.rockcent.common.utils.RBeanUtils;
import com.rockcent.common.utils.RDateFormatUtils;
import com.rockcent.common.utils.RDateUtils;
import com.rockcent.mall.lib.domain.*;
import com.rockcent.mall.lib.domain.enumclass.*;
import com.rockcent.mall.lib.dto.CustomerDto;
import com.rockcent.mall.lib.dto.MerchantCouponDto;
import com.rockcent.mall.lib.dto.ProductDto;
import com.rockcent.mall.lib.dto.ProductEventDto;
import com.rockcent.mall.lib.helper.ProductEventHelper;
import com.rockcent.mall.lib.repository.*;
import com.rockcent.wechat.Routes;
import com.rockcent.wechat.helper.CustomerHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by zhangjh on 2016/10/10.
 */
@RestController
@RequestMapping(value = Routes.API_PREFIX)
public class MerchantController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(MerchantController.class);

    @Autowired
    private MerchantRepository merchantRepository;
    @Autowired
    private MallRepository mallRepository;
    @Autowired
    private ProductEventHelper productEventHelper;
    @Autowired
    private MerchantProductRepository merchantProductRepository;
    @Autowired
    private CategoryRepository categoryRepository;
    @Autowired
    private MerchantCouponRepository merchantCouponRepository;
    @Autowired
    private CustomerHelper customerHelper;
    @Autowired
    private CustomerCouponWalletRepository customerCouponWalletRepository;
    @Autowired
    private MerchantStoreRepository merchantStoreRepository;
    @Autowired
    private MerchantProductMerchantStoresRepository merchantProductMerchantStoresRepository;
    /**
     * @api {get} /api/v2/merchant/get_mobile 查询商户联系电话
     * @apiGroup merchant
     * @apiVersion 1.0.0
     *
     * @apiParam {Long} merchantId 商户ID
     *
     * @apiSuccess {Long} data 商户联系电话
     *
     * @apiSuccessExample {json} Success-Response:
     * {
     *  "code": "1",
     *  "desc": "成功",
     *  "data": "13928552303"
     * }
     */
    @RequestMapping(value= Routes.MERCHANT_GET_MOBILE ,method = RequestMethod.GET)
    @ResponseBody
    public JsonResult getMobile(Long merchantId, HttpServletRequest request){
        RestDoing doing = jr ->{
            if (null == merchantId){
                jr.remind("商户不能为空",log);
                return;
            }
            Merchant merchant = merchantRepository.findOne(merchantId);
            if (null == merchant){
                jr.errorParam(Merchant.REMIND_RECORD_IS_NOT_EXIST,log);
            }
            jr.setData(merchant.getCustomerServiceContact());
        };
        return doing.go(request,log);
    }

    /**
     * @api {get} /api/v2/merchant/index 商家店铺信息
     * @apiGroup merchant
     * @apiVersion 1.0.0
     *
     * @apiParam {Long} mallId 商城ID
     * @apiParam {Long} merchantId 商铺ID
     *
     * @apiSuccess {Long} id 商铺ID
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccess {Long} version 版本
     * @apiSuccess {String} name 商家名称
     * @apiSuccess {String} email 商家邮箱
     * @apiSuccess {String} mobile 手机号码
     * @apiSuccess {String} intro 商城简介
     * @apiSuccess {String} status 状态，UNVERIFY("未认证"),VERIFING("审核中"),VERIFIED("已认证"),DEVERIFY("认证不通过"),DISABLED("已停用")
     * @apiSuccess {Long} userInfoId 用户id
     * @apiSuccess {Long} mallId 平台id
     * @apiSuccess {String} salesCode 分销码
     * @apiSuccess {String} merchantRegisterType 注册类型,MOBILE("手机"), EMAIL("邮件")
     * @apiSuccess {Boolean} prodAudit 是否产品审核
     * @apiSuccess {String} faceUrl 商城封面Url
     * @apiSuccess {String} logoUrl 商城LogoUrl
     * @apiSuccess {String} customerServiceContact 客服联系方式
     *
     * @apiSuccessExample {json} Success-Response:
     * {
     *  "code": "1",
     *  "desc": "成功",
     *  "data": {
     *            "id": 1,
     *            "dateCreated": "2016-05-06 17:30:30",
     *            "lastUpdated": "2016-10-17 14:51:40",
     *            "version": 154,
     *            "name": "哈哈哈哈111",
     *            "email": "renzijian2@rockcent.com",
     *            "mobile": "13928552303",
     *            "intro": "阿斯兰的咖啡机",
     *            "status": "VERIFING",
     *            "userInfoId": 2,
     *            "mallId": 1,
     *            "salesCode": "B@qcXt1RHg",
     *            "merchantRegisterType": "MOBILE",
     *            "prodAudit": false,
     *            "faceUrl": "http://uploads.rockcent.com//dev/merchant/face/201610/81628212267cbc2e13-352c-40f8-9193-508cce903dedLighthouse.jpg",
     *            "logoUrl": "http://uploads.rockcent.com//dev/merchant/logo/201610/131336332032d675e6f-482e-4a2f-8e65-40a42f840110Tulips.jpg",
     *            "customerServiceContact": "15935725896"
     *         }
     *  }
     */
    @RequestMapping(value=Routes.MERCHANT_INDEX,method = RequestMethod.GET)
    @ResponseBody
    public JsonResult index(Long merchantId, HttpServletRequest request){
        RestDoing doing = jr ->{
            if (null == merchantId){
                jr.remind("merchantId:"+ Merchant.CHECK_ID_IS_NOT_NULL,log);
                return;
            }
            if (!merchantRepository.exists(merchantId)){
                jr.errorParam("merchant:"+Merchant.REMIND_RECORD_IS_NOT_EXIST,log);
                return;
            }
            Merchant merchant = merchantRepository.findOne(merchantId);
            if (Whether.YES.equals(merchant.getIsDelete())){
                jr.setData("[]");
                return;
            };
            jr.setData(merchant);
        };
        return doing.go(request,log);
    }
    /**
     * @api {get} /api/v2/merchant/latest_products 新品上市
     * @apiGroup merchant
     * @apiVersion 1.0.0
     *
     * @apiParam {Long} merchantId 商铺ID
     * @apiParam {Integer} pageNo 页码
     * @apiParam {Integer} pageSize 每页记录数
     *
     * @apiSuccess {Long} id 产品ID
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccess {String} type 产品类型
     * @apiSuccess {String} name 产品名称
     * @apiSuccess {BigDecimal} basePrice 原价
     * @apiSuccess {BigDecimal} sellPrice 出售价
     * @apiSuccess {Long} quantity 库存量
     * @apiSuccess {BigDecimal} carriage 运费
     * @apiSuccess {boolean} refundable 是否支持过期退
     * @apiSuccess {String} barcode 产品编码
     * @apiSuccess {boolean} sellnow 是否立即开售
     * @apiSuccess {Date} dateSelling 开售时间
     * @apiSuccess {Long} limitCount 限购数
     * @apiSuccess {String} logoUrl LOGO图
     * @apiSuccess {String} logoUrls LOGO图 多张
     * @apiSuccess {String} note 卖点介绍
     * @apiSuccess {String=SELLING("在售"), SOLDOUT("已下架"), EXPIRED("已过期"), DELETED("已删除"), WAIT_APPLY("待申请"), WAIT_AUDIT("待审核"), AUDIT_PASS("审核通过"), AUDIT_FAIL("审核不通过")} status 产品状态
     * @apiSuccess {Long} mallId 平台ID
     * @apiSuccess {Long} merchantId 商家ID
     * @apiSuccess {String} serveRate 服务费比率
     * @apiSuccess {String=SHOP_PICKUP("到店自取"), SHIPPING("物流"), SHOP_PICKUP_AND_SHIPPING("物流及到店自取")} shippingType 支持的物流类型
     * @apiSuccess {String} resellFee 分销佣金
     * @apiSuccess {String} shareFee 分享返利
     * @apiSuccess {String} merchantName 产品所属商家名称
     * @apiSuccess {Boolean} recommend 是否在分销市场展示
     * @apiSuccess {Integer} totalCount 总记录数
     * @apiSuccess {Integer} totalPage 总页数
     * @apiSuccess {Integer} pageNo 当前页
     * @apiSuccess {Integer} pageSize 每页记录数
     *
     * @apiSuccessExample {json} Success-Response:
     * {
     *  "code": "1",
     *  "desc": "成功",
     *  "data":{
     *         "data": [
     *                      {
     *                          "id": 311,
     *                          "dateCreated": "2016-10-13 17:26:15",
     *                          "lastUpdated": "2016-10-13 17:26:15",
     *                          "version": 0,
     *                          "name": "Bi@ch",
     *                          "type": "GOODS",
     *                          "basePrice": 123,
     *                          "sellPrice": 12,
     *                          "quantity": 12,
     *                          "carriage": 0,
     *                          "refundable": false,
     *                          "barcode": "",
     *                          "sellnow": true,
     *                          "dateSelling": "2016-10-13 17:26:16",
     *                          "limitCount": 0,
     *                          "logoUrl": "http://uploads.rockcent.com//dev/product/face/201610/131725478706ea3fe0c-e7bb-4572-86e4-58f7d1248fa9nyantocat.gif",
     *                          "logoUrls": "[\"http://uploads.rockcent.com//dev/product/face/201610/131725478706ea3fe0c-e7bb-4572-86e4-58f7d1248fa9nyantocat.gif\"]",
     *                          "note": "Gif",
     *                          "status": "SELLING",
     *                          "mallId": 1,
     *                          "merchantId": 2,
     *                          "serveRate": "24",
     *                          "shippingType": "SHIPPING",
     *                          "resellFee": 0,
     *                          "shareFee": 0,
     *                          "merchantName": "b1测试商户 X",
     *                          "recommend": false
     *                        },
     *                    ...
     *                  ],
     *                  "totalCount": 127,
     *                  "totalPage": 13,
     *                  "pageNo": 1,
     *                  "pageSize": 10
     *
     *          }
     *  }
     */
    @RequestMapping(value=Routes.MERCHANT_LATEST_PRODUCTS,method = RequestMethod.GET)
    @ResponseBody
    public JsonResult latestProducts(ProductDto productDto , HttpServletRequest request){
        CustomerDto customerDto = customerHelper.getSession(request);
        RestDoing doing = jr ->{
            if (null == productDto.getMerchantId()){
                jr.remind("merchantId:"+Merchant.CHECK_ID_IS_NOT_NULL,log);
                return;
            }
            if (null == productDto.getPageNo()){
                jr.remind("请正确输入页码",log);
                return;
            }
            if (null == productDto.getPageSize()){
                jr.remind("请正确输入页数",log);
                return;
            }
            if (!merchantRepository.exists(productDto.getMerchantId())){
                jr.errorParam("merchant:"+Merchant.REMIND_RECORD_IS_NOT_EXIST,log);
                return;
            }
            PageResult<Product> pageResult1 = merchantProductRepository.getMerchantLatestProducts( customerDto.getMallId(),  productDto.getMerchantId(),  this.getPage(productDto.getPageNo(),productDto.getPageSize()));

            //记录浏览记录
            ProductEventDto productEventDto = new ProductEventDto();
            productEventDto.setEventType(ProductEventType.VIEWED);
            productEventDto.setCustomerId(customerDto.getId());
            productEventDto.setCustomerName(customerDto.getNickName());
            productEventHelper.view(pageResult1.data,productEventDto);

            jr.setData(pageResult1);
        };
        return doing.go(request,log);
    }


    /**
     * @api {get} /api/v2/merchant/list_products 产品列表
     * @apiGroup merchant
     * @apiVersion 1.0.0
     *
     * @apiParam {Long} mallId  商城ID
     * @apiParam {Long} merchantId 商铺ID
     * @apiParam {Integer} pageNo 页码
     * @apiParam {Integer} pageSize 每页记录数
     * @apiParam {String} [orderBy] 排序字段：(忽略大小写)saleCount(销量),sellPrice(售价),dateCreated(创建时间)，不传该参数时默认使用date_created，如果传了saleCount，只有按销量升序
     * @apiParam {String} [sort] 排序方式：(忽略大小写)desc(降序)，asc(升序)，不传该参数时默认使用desc
     *
     * @apiSuccess {Long} id 产品ID
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccess {Long} version 版本
     * @apiSuccess {String} type 产品类型
     * @apiSuccess {String} name 产品名称
     * @apiSuccess {BigDecimal} basePrice 原价
     * @apiSuccess {BigDecimal} sellPrice 出售价
     * @apiSuccess {Long} quantity 库存量
     * @apiSuccess {BigDecimal} carriage 运费
     * @apiSuccess {boolean} refundable 是否支持过期退
     * @apiSuccess {String} barcode 产品编码
     * @apiSuccess {boolean} sellnow 是否立即开售
     * @apiSuccess {Date} dateSelling 开售时间
     * @apiSuccess {Long} limitCount 限购数
     * @apiSuccess {String} logoUrl LOGO图
     * @apiSuccess {String} logoUrls LOGO图 多张
     * @apiSuccess {String} note 卖点介绍
     * @apiSuccess {String=SELLING("在售"), SOLDOUT("已下架"), EXPIRED("已过期"), DELETED("已删除"), WAIT_APPLY("待申请"), WAIT_AUDIT("待审核"), AUDIT_PASS("审核通过"), AUDIT_FAIL("审核不通过")} status 产品状态
     * @apiSuccess {Long} mallId 平台ID
     * @apiSuccess {Long} merchantId 商家ID
     * @apiSuccess {String} serveRate 服务费比率
     * @apiSuccess {String=SHOP_PICKUP("到店自取"), SHIPPING("物流"), SHOP_PICKUP_AND_SHIPPING("物流及到店自取")} shippingType 支持的物流类型
     * @apiSuccess {String} resellFee 分销佣金
     * @apiSuccess {String} shareFee 分享返利
     * @apiSuccess {String} merchantName 产品所属商家名称
     * @apiSuccess {Boolean} recommend 是否在分销市场展示
     * @apiSuccess {Integer} totalCount 总记录数
     * @apiSuccess {Integer} totalPage 总页数
     * @apiSuccess {Integer} pageNo 当前页
     * @apiSuccess {Integer} pageSize 每页记录数
     *
     * @apiSuccessExample {json} Success-Response:
     * {
     *  "code": "1",
     *  "desc": "成功",
     *  "data": {
     *      "data": [
     *                  {
     *                      "id": 46,
     *                      "dateCreated": "2016-05-18 14:48:45",
     *                      "lastUpdated": "2016-07-15 15:48:29",
     *                      "version": 4,
     *                      "name": "产品1",
     *                      "type": "GOODS",
     *                      "basePrice": 101,
     *                      "sellPrice": 100,
     *                      "quantity": 17,
     *                      "carriage": 0,
     *                      "refundable": false,
     *                      "sellnow": true,
     *                      "dateSelling": "2016-05-18 14:48:19",
     *                      "limitCount": 0,
     *                      "logoUrl": "/20160518/20160518144720FMH5QCmF.jpg",
     *                      "note": "dfas",
     *                      "status": "SELLING",
     *                      "mallId": 1,
     *                      "merchantId": 2,
     *                      "serveRate": "2.5",
     *                      "shippingType": "SHIPPING",
     *                      "resellFee": 5,
     *                      "shareFee": 2,
     *                      "recommend": false
     *                  },
     *                       ...
     *             ],
     *              "totalCount": 131,
     *              "totalPage": 14,
     *              "pageNo": 1,
     *              "pageSize": 10
     *          }
     *  }
     */
    @RequestMapping(value=Routes.MERCHANT_LIST_PRODUCTS,method = RequestMethod.GET)
    @ResponseBody
    public JsonResult listProducts(ProductDto productDto , HttpServletRequest request){
        CustomerDto customerDto = customerHelper.getSession(request);
        RestDoing doing = jr ->{
            //商城、商铺验证
            if (null == productDto.getMerchantId()){
                jr.remind("merchantId:"+Merchant.CHECK_ID_IS_NOT_NULL,log);
                return;
            }
            if (null == productDto.getPageNo()){
                jr.remind("请正确输入页码",log);
                return;
            }
            if (null == productDto.getPageSize()){
                jr.remind("请正确输入页数",log);
                return;
            }
            if (!merchantRepository.exists(productDto.getMerchantId())){
                jr.errorParam("merchant:"+Merchant.REMIND_RECORD_IS_NOT_EXIST,log);
                return;
            }
            productDto.setMallId(customerDto.getMallId());
            //排序条件,不传默认为dateCreated desc 创建时间降序
            PageResult<Product> productPageResult = merchantProductRepository.getProductListPageResult(productDto,this.getPage(productDto.getPageNo(),productDto.getPageSize()));
            //记录浏览记录
            ProductEventDto productEventDto = new ProductEventDto();
            productEventDto.setEventType(ProductEventType.VIEWED);
            productEventDto.setCustomerId(customerDto.getId());
            productEventDto.setCustomerName(customerDto.getNickName());
            productEventHelper.view(productPageResult.data,productEventDto);

            jr.setData(productPageResult);

        };
        return doing.go(request,log);
    }

    /**
     * @api {get} /api/v2/merchant/advising_products 精品推荐
     * @apiGroup merchant
     * @apiVersion 1.0.0
     *
     * @apiParam {Long} merchantId 商铺ID
     * @apiParam {Integer} pageNo 页码
     * @apiParam {Integer} pageSize 每页记录数
     *
     * @apiSuccess {Long} id 产品ID
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccess {Long} version 版本
     * @apiSuccess {String} type 产品类型
     * @apiSuccess {String} name 产品名称
     * @apiSuccess {BigDecimal} basePrice 原价
     * @apiSuccess {BigDecimal} sellPrice 出售价
     * @apiSuccess {Long} quantity 库存量
     * @apiSuccess {BigDecimal} carriage 运费
     * @apiSuccess {boolean} refundable 是否支持过期退
     * @apiSuccess {String} barcode 产品编码
     * @apiSuccess {boolean} sellnow 是否立即开售
     * @apiSuccess {Date} dateSelling 开售时间
     * @apiSuccess {Long} limitCount 限购数
     * @apiSuccess {String} logoUrl LOGO图
     * @apiSuccess {String} logoUrls LOGO图 多张
     * @apiSuccess {String} note 卖点介绍
     * @apiSuccess {String=SELLING("在售"), SOLDOUT("已下架"), EXPIRED("已过期"), DELETED("已删除"), WAIT_APPLY("待申请"), WAIT_AUDIT("待审核"), AUDIT_PASS("审核通过"), AUDIT_FAIL("审核不通过")} status 产品状态
     * @apiSuccess {Long} mallId 平台ID
     * @apiSuccess {Long} merchantId 商家ID
     * @apiSuccess {String} serveRate 服务费比率
     * @apiSuccess {String=SHOP_PICKUP("到店自取"), SHIPPING("物流"), SHOP_PICKUP_AND_SHIPPING("物流及到店自取")} shippingType 支持的物流类型
     * @apiSuccess {String} resellFee 分销佣金
     * @apiSuccess {String} shareFee 分享返利
     * @apiSuccess {String} merchantName 产品所属商家名称
     * @apiSuccess {Boolean} recommend 是否在分销市场展示
     * @apiSuccess {Integer} totalCount 总记录数
     * @apiSuccess {Integer} totalPage 总页数
     * @apiSuccess {Integer} pageNo 当前页
     * @apiSuccess {Integer} pageSize 每页记录数
     *
     * @apiSuccessExample {json} Success-Response:
     * {
     *  "code": "1",
     *  "desc": "成功",
     *  "data": {
     *     "data": [
     *              {
     *                  "id": 305,
     *                  "dateCreated": "2016-10-13 16:01:26",
     *                  "lastUpdated": "2016-10-13 16:01:26",
     *                  "version": 1,
     *                  "name": "gfg",
     *                  "type": "GOODS",
     *                  "basePrice": 34,
     *                  "sellPrice": 34,
     *                  "quantity": 34,
     *                  "carriage": 0,
     *                  "refundable": false,
     *                  "barcode": "",
     *                  "sellnow": true,
     *                  "dateSelling": "2016-10-13 16:01:27",
     *                  "limitCount": 0,
     *                  "logoUrl": "http://uploads.rockcent.com//dev/product/face/201610/131612062b284a9b6-a005-4b1f-b227-38d031607e5ebannerCase.png",
     *                  "logoUrls": "[\"http://uploads.rockcent.com//dev/product/face/201610/131612062b284a9b6-a005-4b1f-b227-38d031607e5ebannerCase.png\"]",
     *                  "note": "sffs",
     *                  "status": "SELLING",
     *                  "mallId": 1,
     *                  "merchantId": 1,
     *                  "merchantName": "哈哈哈哈111",
     *                  "serveRate": "24",
     *                  "shippingType": "SHIPPING",
     *                  "resellFee": 21,
     *                  "shareFee": 20,
     *                  "recommend": false
     *              },
     *                  ...
     *           ],
     *          "totalCount": 116,
     *          "totalPage": 12,
     *          "pageNo": 1,
     *          "pageSize": 10
     *      }
     * }
     */
    @RequestMapping(value=Routes.MERCHANT_ADVISING_PRODUCTS,method = RequestMethod.GET)
    @ResponseBody
    public JsonResult advisingProducts(ProductDto productDto , HttpServletRequest request){
        CustomerDto customerDto = customerHelper.getSession(request);
        RestDoing doing = jr ->{
            //商城、商铺验证
            if (null == productDto.getMerchantId()){
                jr.remind("merchantId:"+Merchant.CHECK_ID_IS_NOT_NULL,log);;
                return;
            }
            if (null == productDto.getPageNo()){
                jr.remind("请正确输入页码",log);
                return;
            }
            if (null == productDto.getPageSize()){
                jr.remind("请正确输入页数",log);
                return;
            }
            Merchant merchant = merchantRepository.findByIdAndMallId(productDto.getMerchantId(),customerDto.getMallId());
            if (null == merchant){
                jr.errorParam("merchant:"+Merchant.REMIND_RECORD_IS_NOT_EXIST,log);;
                return;
            }
            productDto.setMallId(customerDto.getMallId());
            PageResult pageResult = new PageResult<Product>(productDto.getPageNo(),productDto.getPageSize());
            PageResult<Product> productPageResult = merchantProductRepository.getAdvisingProduct(productDto,pageResult);
            jr.setData(productPageResult);
            //记录浏览记录
            ProductEventDto productEventDto = new ProductEventDto();
            productEventDto.setEventType(ProductEventType.VIEWED);
            productEventDto.setCustomerId(customerDto.getId());
            productEventDto.setCustomerName(customerDto.getNickName());
            productEventHelper.view(productPageResult.data,productEventDto);
        };
        return doing.go(request,log);
    }

    /**
     * @api {get} /api/v2/merchant/get_categories 查询某商家下的分类列表
     * @apiGroup merchant
     * @apiVersion 1.0.0
     *
     * @apiParam {Long} mallId  商城ID
     * @apiParam {Long} merchantId 商铺ID
     * @apiParam {Integer} pageNo 页码
     * @apiParam {Integer} pageSize 每页记录数
     *
     * @apiSuccess {Long} id 产品ID
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccess {Long} version 版本
     * @apiSuccess {String} name 名称
     * @apiSuccess {String} logoUrl 图标Url
     * @apiSuccess {Boolean} visible 是否可见
     * @apiSuccess {Integer} displayOrderId 显示顺序
     * @apiSuccess {String} note 描述
     * @apiSuccess {String} mallId 平台Id
     * @apiSuccess {String} parentId 父品类
     *
     * @apiSuccessExample {json} Success-Response:
     * {
     *  "code": "1",
     *  "desc": "成功",
     *  "data": [
     *              {
     *                  "id": 295,
     *                  "dateCreated": "2016-08-22 16:42:36",
     *                  "lastUpdated": "2016-08-23 11:29:14",
     *                  "version": 8,
     *                  "name": "5555",
     *                  "logoUrl": "/20160823/20160823112912X2i0RmEQ.png",
     *                  "visible": true,
     *                  "displayOrderId": 134,
     *                  "mallId": 1,
     *                  "parentId": 289
     *              },
     *              ...
     *          ]
     *  }
     *
     */
    @RequestMapping(value=Routes.MERCHANT_GET_CATEGORIES,method = RequestMethod.GET)
    @ResponseBody
    public JsonResult getCatetories(Long mallId,Long merchantId , HttpServletRequest request){
        RestDoing doing = jr ->{
            if (null == mallId){
                jr.remind("mallId:"+Mall.CHECK_ID_IS_NOT_NULL,log);
                return;
            }
            if (null == merchantId){
                jr.remind("merchantId:"+Merchant.CHECK_ID_IS_NOT_NULL,log);
                return;
            }
            if( !mallRepository.exists(mallId) ){
                jr.errorParam("mall:"+Mall.REMIND_RECORD_IS_NOT_EXIST,log);
                return;
            }
            if (!merchantRepository.exists(merchantId)){
                jr.errorParam("merchant:"+Merchant.REMIND_RECORD_IS_NOT_EXIST,log);
                return;
            }
            List<Category> categoryList = categoryRepository.getCategoryList(mallId,merchantId);
            jr.setData(categoryList);
        };
        return doing.go(request,log);
    }
    /**
     * @api {get} /api/v2/merchant/search 商家下的搜索
     * @apiGroup merchant
     * @apiVersion 1.0.0
     *
     * @apiParam {Long} mallId  商城ID
     * @apiParam {Long} merchantId 商铺ID
     * @apiParam {String} keyword 关键字
     * @apiParam {String} orderBy 排序字段：ALL(综合排序)，saleCount(销量只有降序)，sellPrice(价格)，默认按综合排序
     * @apiParam {String} sort 排序方式 :desc（降序），asc（升序），默认降序
     * @apiParam {Integer} pageNo 页码
     * @apiParam {Integer} pageSize 每页记录数
     *
     * @apiSuccess {Long} id ID
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccess {Long} version 版本
     * @apiSuccess {String} identifier 产品唯一的识别码
     * @apiSuccess {String} name 名称
     * @apiSuccess {String} type 类型 ALL("全部"), GOODS("商品"), SERVICE("服务")
     * @apiSuccess {BigDecimal} basePrice 原价
     * @apiSuccess {BigDecimal} sellPrice 售价
     * @apiSuccess {Long} quantity 库存数量
     * @apiSuccess {BigDecimal} carriage 运费
     * @apiSuccess {Boolean} refundable 是否支持过期退
     * @apiSuccess {Boolean} sellnow 是否立即开售
     * @apiSuccess {Date} dateSelling 开售时间
     * @apiSuccess {Long} limitCount 限购数量
     * @apiSuccess {String} logoUrl LOGO图
     * @apiSuccess {String} note 卖点介绍
     * @apiSuccess {String} status 状态 SELLING("在售"), SUPPLIER_CANCEL_SOLDOUT("分销市场 供应商取消供货 已下架"),DISTRIBUTOR_CANCEL_SOLDOUT("分销市场 分销商取消代销 已下架"), SOLDOUT("已下架"), EXPIRED("已过期"), DELETED("已删除"), WAIT_APPLY("待申请"), WAIT_AUDIT("待审核"), AUDIT_PASS("审核通过"), AUDIT_FAIL("审核不通过")
     * @apiSuccess {Long} mallId 商城 id
     * @apiSuccess {Long} merchantId 商家 id
     * @apiSuccess {String} serveRate 服务费比率
     * @apiSuccess {String} shippingType 支持的物流类型 SHOP_PICKUP("到店自取"), SHIPPING("物流"), SHOP_PICKUP_AND_SHIPPING("物流及到店自取")
     * @apiSuccess {BigDecimal} resellFee 分销佣金
     * @apiSuccess {BigDecimal} shareFee 分享返利
     * @apiSuccess {Boolean} recommend 是否在分销市场展示
     * @apiSuccess {Integer} totalCount 总记录数
     * @apiSuccess {Integer} totalPage 总页数
     * @apiSuccess {Integer} pageNo 页码
     * @apiSuccess {Integer} pageSize 每页记录数
     *
     * @apiSuccessExample {json} Success-Response:
     *
     * {
     *  "code": "1",
     *  "desc": "成功",
     *  "data": {
     *  "data": [
     *              {
     *                  "id": 30,
     *                  "dateCreated": "2016-05-13 18:09:34",
     *                  "lastUpdated": "2016-05-19 10:12:02",
     *                  "version": 46,
     *                  "name": "测试BDC不可退！",
     *                  "type": "SERVICE",
     *                  "basePrice": 100,
     *                  "sellPrice": 99,
     *                  "quantity": 957,
     *                  "carriage": 0,
     *                  "refundable": false,
     *                  "sellnow": true,
     *                  "dateSelling": "2016-05-15 10:37:46",
     *                  "limitCount": 0,
     *                  "logoUrl": "http://upload.dev.rockcent.com/images/20160513/20160513180613J2f5pAK6.jpg",
     *                  "note": "卖点介绍",
     *                  "status": "SELLING",
     *                  "mallId": 1,
     *                  "merchantId": 2,
     *                  "serveRate": "2.5",
     *                  "resellFee": 4,
     *                  "shareFee": 0,
     *                  "marketPlatformType": "IN_PLATFORM",
     *                  "recommend": false
     *              },
     *                  ...
     *          ],
     *          "totalCount": 150,
     *          "totalPage": 30,
     *          "pageNo": 0,
     *          "pageSize": 5
     *  }
     */
    @RequestMapping(value=Routes.MERCHANT_SEARCH,method = RequestMethod.GET)
    @ResponseBody
    public JsonResult search(String keyword,ProductDto productDto , HttpServletRequest request){
        CustomerDto customerDto = customerHelper.getSession(request);
        RestDoing doing = jr ->{
            //商城、商铺验证
            if (null == productDto.getMerchantId()){
                jr.remind("merchantId:"+Merchant.CHECK_ID_IS_NOT_NULL,log);
                return;
            }
            if (null == productDto.getPageNo()){
                jr.remind("请正确输入页码",log);
                return;
            }
            if (null == productDto.getPageSize()){
                jr.remind("请正确输入页数",log);
                return;
            }
            if (!merchantRepository.exists(productDto.getMerchantId())){
                jr.errorParam("merchant:"+Merchant.REMIND_RECORD_IS_NOT_EXIST,log);
                return;
            }
            if ("saleCount".equalsIgnoreCase(productDto.getOrderBy())){
                productDto.setOrderBy("saleCount");
                productDto.setSort("desc");
            }else {
                productDto.setOrderBy("sellPrice".equalsIgnoreCase(productDto.getOrderBy())?"sellPrice":"ALL");
                productDto.setSort("asc".equalsIgnoreCase(productDto.getSort())?"asc":"desc");
            }
            productDto.setMallId(customerDto.getMallId());
            PageResult pageResult = new PageResult(productDto.getPageNo(),productDto.getPageSize());
            // 排序 综合/销量/价格
            PageResult pageResult1 = merchantProductRepository.merchantSearch(productDto, ProductStatus.SELLING,keyword,pageResult);
            jr.setData(pageResult1);

            //记录浏览记录
            ProductEventDto productEventDto = new ProductEventDto();
            productEventDto.setEventType(ProductEventType.VIEWED);
            productEventDto.setCustomerId(customerDto.getId());
            productEventDto.setCustomerName(customerDto.getNickName());
            productEventHelper.view(pageResult1.data,productEventDto);
        };
        return doing.go(request,log);
    }
    /**
     * @api {get} /api/v2/merchant/coupons 商家下的可领票券列表
     * @apiGroup merchant
     * @apiVersion 1.0.0
     *
     * @apiParam {Long} merchantId 商铺ID
     * @apiParam {Long} [productId] 商品ID，不传该值时，按商家查询票券，传该值时，按商家和产品查
     *
     * @apiSuccess {Long} id 券ID
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccess {Long} version 版本
     * @apiSuccess {String} type 类型 VOUCHERS("抵用券"), DISCOUNT("折扣券")
     * @apiSuccess {String} name 名称
     * @apiSuccess {String} barCode 唯一编号
     * @apiSuccess {BigDecimal} faceValue 面值(抵用券)
     * @apiSuccess {BigDecimal} discount 享受折扣(折扣券)
     * @apiSuccess {BigDecimal} limitAmount 最低消费金额
     * @apiSuccess {Long} quantity 发放数量
     * @apiSuccess {Date} dateEnabled 有效期开始时间
     * @apiSuccess {Date} dateDisabled 有效期结束时间
     * @apiSuccess {String} useScope 适用范围 ALL_STORE("所有门店"), ALL_PRODUCT("所有产品"), PART_STORE("指定门店"), PART_PRODUCT("指定产品")
     * @apiSuccess {Date} dateIssued 发放时间
     * @apiSuccess {String} drawLimit 领取限制 NO("没有上限"), ALL("总共上限"), DAYS("每天上限")
     * @apiSuccess {Long} limitCount 限制数量
     * @apiSuccess {String} sharing 是否共享 YES("是"), NO("否")
     * @apiSuccess {String} showOnCenter 是否发布到领券中心 YES("是"), NO("否")
     * @apiSuccess {String} showOnMerchant 是否发布到店铺首页 YES("是"), NO("否")
     * @apiSuccess {String} logoUrl LOGO图
     * @apiSuccess {String} introduction 使用说明
     * @apiSuccess {String} status 状态 WAIT_ISSUE("待发放"), ISSUED("已发放"), SOLDOUT("已下架"), EXPIRED("已过期"), DELETED("已删除")
     * @apiSuccess {Long} merchantId 商家ID
     * @apiSuccess {String} merchantName 商铺名称
     * @apiSuccess {Integer} leaveTotal 剩余数量
     * @apiSuccess {Boolean} hadToke 用户是否已经领取
     *
     *
     * @apiSuccessExample {json} Success-Response:
     * {
        "code": "1",
        "desc": "成功",
        "data": [
                    {
                        "id": 44,
                        "dateCreated": "2016-08-05 18:27:29",
                        "lastUpdated": "2016-08-05 18:27:30",
                        "type": "VOUCHERS",
                        "name": "anti",
                        "barCode": "123",
                        "faceValue": 11,
                        "discount": 1,
                        "limitAmount": 123,
                        "quantity": 12,
                        "dateEnabled": "2016-08-05 00:00:00",
                        "dateDisabled": "2017-08-05 00:00:00",
                        "useScope": "PART_PRODUCT",
                        "dateIssued": "2016-08-05 18:26:00",
                        "drawLimit": "NO",
                        "limitCount": 0,
                        "sharing": "NO",
                        "showOnCenter": "NO",
                        "showOnMerchant": "YES",
                        "logoUrl": "/20160805/20160805182632ZR5WvbI8.jpg",
                        "introduction": "heyhey",
                        "status": "ISSUED",
                        "merchantId": 1,
                        "merchantName": "asd",
                        "leaveTotal": 12,
                        "verifiedCount": 0,
                        "productList": [],
                        "hadToken": false,
                        "storeList": []
                    },
                     ...
                ]
        }
     */
    @RequestMapping(value=Routes.MERCHANT_COUPONS,method = RequestMethod.GET)
    @ResponseBody
    public JsonResult merchantCoupons(Long merchantId,Long productId, HttpServletRequest request){
        RestDoing doing = jr ->{
            if (productId!=null&&!merchantProductRepository.exists(productId)){
                jr.errorParam("product:"+Product.REMIND_RECORD_IS_NOT_EXIST,log);
                return;
            }
            if (merchantId==null){
                jr.remind("merchantId is null",log);
                return;
            }
            CustomerDto customerDto = customerHelper.getSession(request);

            List<Long> customerCouponList1 =null;
            if (customerDto!=null){
                //用户已从领券中心领取的券
                List<CustomerCouponWallet> customerCouponWalletList = customerCouponWalletRepository.findByCustomerId(customerDto.getId());
                customerCouponList1 = customerCouponWalletList.stream().map(CustomerCouponWallet::getCouponId).collect(Collectors.toList());
            }
            //lambda表达式的需要，不能传变化的值
            List<Long> customerCouponList = customerCouponList1;
            //productId不为空时，查出该商品能够使用的券
            List<Long> couponIds = null;
            if (productId!=null){
                Product product = merchantProductRepository.findOne(productId);
                List<MerchantCoupon> merchantCouponList =  merchantCouponRepository.getUseableCoupons(product);
                List<MerchantCoupon> allMerchantCouponList = merchantCouponRepository.findByMerchantIdAndUseScope(product.getMerchantId(), CouponUseScope.ALL_PRODUCT);
                merchantCouponList.addAll(allMerchantCouponList);
                couponIds = merchantCouponList.stream().map(MerchantCoupon::getId).collect(Collectors.toList());
            }
            //商铺下可领取的券
            List<MerchantCoupon> merchantCouponList = merchantCouponRepository.findByMerchantIdAndCouponIds(merchantId,couponIds);
            String merchantName = merchantRepository.getOne(merchantId).getName();
            //设置数据
            List merchantCouponDtoList = merchantCouponList.stream().map(merchantCoupon -> {
                MerchantCouponDto merchantCouponDto = new MerchantCouponDto();
                RBeanUtils.copyProperties(merchantCoupon,merchantCouponDto);
                //枚举类型数据
                merchantCouponDto.setType(merchantCoupon.getType().toString());
                merchantCouponDto.setLimitAmount(merchantCoupon.getLimitAmount().doubleValue());
                merchantCouponDto.setDateDisabled(merchantCoupon.getDateDisabled());
                merchantCouponDto.setDateEnabled(merchantCoupon.getDateEnabled());
                merchantCouponDto.setUseScope(merchantCoupon.getUseScope().toString());
                merchantCouponDto.setDrawLimit(merchantCoupon.getDrawLimit().toString());
                merchantCouponDto.setSharing(merchantCoupon.getSharing().toString());
                merchantCouponDto.setShowOnCenter(merchantCoupon.getShowOnCenter().toString());
                merchantCouponDto.setShowOnMerchant(merchantCoupon.getShowOnMerchant().toString());
                merchantCouponDto.setStatus(merchantCoupon.getStatus().toString());
                //设置商铺名称
                merchantCouponDto.setMerchantName(merchantName);
                //设置是否已领取券
                if (customerCouponList!=null && customerCouponList.contains(merchantCoupon.getId())) {
                    merchantCouponDto.setHadToken(true);
                }
                return merchantCouponDto;
            }).collect(Collectors.toList());

            jr.setData(merchantCouponDtoList);

        };
        return doing.go(request,log);
    }
    /**
     * @api{get} /api/v2/merchant/store/list 商家旗下所有门店列表
     * @apiGroup merchant
     *
     * @apiHeader {String} domain 平台
     * @apiParam {Long} merchant 商家id
     *
     * @apiSuccess {Long} id 门店ID
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccess {Long} version 版本
     * @apiSuccess {String} name 名称
     * @apiSuccess {String} type 类型 STORE("实体店"), SHOP("网店")
     * @apiSuccess {String} address 地址
     * @apiSuccess {String} third 网店(网址)
     * @apiSuccess {String} phone 电话(手机/座机)
     * @apiSuccess {Long} locationId 地区ID
     * @apiSuccess {String} status 状态 ENABLE("启用"), DISABLE("停用")
     * @apiSuccess {String} number 门店编号(生成规则 001 - 999)
     * @apiSuccess {String} exchange 是否支持现有所有产品在此店兑换或自提(是:YES,否:NO)
     * @apiSuccess {String} introduction 介绍
     * @apiSuccess {Long} merchantId 商家 id
     * @apiSuccess {Long} mallId 平台ID
     *
     *
     * @apiSuccessExample {json} Success-Response:
     * {
     *  "code": "1",
     *  "desc": "成功",
     *  "data": [
     *              {
     *                  "id": 1,
     *                  "dateCreated": "2016-05-05 18:16:12",
     *                  "lastUpdated": "2016-10-11 18:51:48",
     *                  "version": 0,
     *                  "name": "甜店",
     *                  "type": "STORE",
     *                  "address": "越秀区",
     *                  "phone": "18216280038,,",
     *                  "locationId": 440104,
     *                  "status": "ENABLE",
     *                  "number": "001",
     *                  "exchange": "YES",
     *                  "introduction": "卖点超好",
     *                  "merchantId": 2
     *              },
     *               ...
     *          ]
     *  }
     */
    @RequestMapping(value=Routes.MERCHANT_STORE_LIST,method = RequestMethod.GET)
    @ResponseBody
    public JsonResult listStore(Long merchantId, HttpServletRequest request){
        CustomerDto customerDto = customerHelper.getSession(request);
        RestDoing doing = jr ->{
            if (merchantId == null){
                jr.remind("商铺ID不能为空",log);
                return;
            }
//            log.info("listStore merchantId:{}",merchantId);
            Merchant merchant = merchantRepository.findOne(merchantId);
            Long mId=0L;
            if(merchant!=null) {
                mId = merchant.getMallId();
            }
//            log.info("merchant.mallId:{},customerDTO.mallId:{}",mId,customerDto.getMallId());
            //商铺需要在同平台下
            if (merchant == null || merchant.getMallId()!= customerDto.getMallId()){
                jr.errorParam("该商铺不存在",log);
                return;
            }
            List<MerchantStore> merchantStoreList = merchantStoreRepository.findByMerchantIdAndStatusAndExchangeAndMallId(merchantId,MerchantStoreStatus.ENABLE, Whether.YES,customerDto.getMallId());

            jr.setData(merchantStoreList);
        };
        return doing.go(request,log);
    }
    /**
     * @api{get} /api/v2/merchant/store/list_by_product 产品适合兑换的所有门店列表（服务，自提）
     * @apiGroup merchant
     *
     * @apiHeader {String} domain 平台
     * @apiParam {Long} productId 产品id
     *
     * @apiSuccess {Long} id 门店ID
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccess {Long} version 版本
     * @apiSuccess {String} name 名称
     * @apiSuccess {String} type 类型 STORE("实体店"), SHOP("网店")
     * @apiSuccess {String} address 地址
     * @apiSuccess {String} third 网店(网址)
     * @apiSuccess {String} phone 电话(手机/座机)
     * @apiSuccess {Long} locationId 地区ID
     * @apiSuccess {String} status 状态 ENABLE("启用"), DISABLE("停用")
     * @apiSuccess {String} number 门店编号(生成规则 001 - 999)
     * @apiSuccess {String} exchange 是否支持现有所有产品在此店兑换或自提(是:YES,否:NO)
     * @apiSuccess {String} introduction 介绍
     * @apiSuccess {Long} merchantId 商家 id
     * @apiSuccess {Long} mallId 平台ID
     *
     *
     * @apiSuccessExample {json} Success-Response:
     * {
     *  "code": "1",
     *  "desc": "成功",
     *  "data": [
     *              {
     *                  "id": 15,
     *                  "dateCreated": "2016-07-28 19:06:03",
     *                  "lastUpdated": "2016-10-11 18:51:48",
     *                  "version": 0,
     *                  "name": "音乐会",
     *                  "type": "STORE",
     *                  "address": "是地热个",
     *                  "phone": "13450286811",
     *                  "locationId": 440101,
     *                  "status": "ENABLE",
     *                  "number": "001",
     *                  "exchange": "YES",
     *                  "introduction": "发鬼地方的",
     *                  "merchantId": 52
     *              }
     *          ]
     *  }
     */
    @RequestMapping(value=Routes.MERCHANT_STORE_LIST_BY_PRODUCT,method = RequestMethod.GET)
    @ResponseBody
    public JsonResult listByProduct(Long productId, HttpServletRequest request){
        CustomerDto customerDto = customerHelper.getSession(request);
        RestDoing doing = jr ->{
            if (productId==null){
                jr.remind("产品ID不能为空",log);
                return;
            }
            Product product = merchantProductRepository.findByIdAndIsDelete(productId,Whether.NO);
            if (product == null){
                jr.errorParam("产品不存在",log);
                return;
            }
            //商家ID
            Long productMerchantId = product.getMerchantId();
            if(productMerchantId==null || productMerchantId.longValue()==0) {
                jr.errorParam("产品商家不存在",log);
                return;
            }
            //查询用的产品ID，
            Long searchId = productId;
            //检测商品是否分销
            if (product.getMarketId()!=null){
                //是分销产品时，用marketId
                searchId = product.getMarketId();
                //如果是分销产品用原产品的商家ID来查询门店
                Product OriginalProduct = merchantProductRepository.findByIdAndIsDelete(product.getMarketId(),Whether.NO);
                if(OriginalProduct!=null) {
                    productMerchantId = OriginalProduct.getMerchantId();
                }
            }
            List<MerchantStore> merchantStoreList = new ArrayList<>();
            if (ProductMerchantStoreType.PART.equals(product.getProductMerchantStoreType())){
                //是指定门店时，part
                List<ProductMerchantStores> productMerchantStoresList = merchantProductMerchantStoresRepository.findByProductId(searchId);
                List<Long> storesIdList = productMerchantStoresList.stream().map(ProductMerchantStores::getMerchantStoreId).collect(Collectors.toList());
                merchantStoreList = merchantStoreRepository.findByStatusAndExchangeAndIdInAndMallId(MerchantStoreStatus.ENABLE, Whether.YES ,storesIdList,customerDto.getMallId());
            }else {
                //是所有门店时，all
                merchantStoreList = merchantStoreRepository.findByMerchantIdAndStatusAndExchangeAndMallId(productMerchantId,MerchantStoreStatus.ENABLE, Whether.YES,customerDto.getMallId());
            }
            jr.setData(merchantStoreList);
        };
        return doing.go(request,log);
    }
    /**
     * @api{get} /api/v2/merchant/store 查询门店
     * @apiGroup merchant
     *
     * @apiHeader {String} domain 平台
     * @apiHeader {String} userToken 用户token
     * @apiParam {Long} storeId 店铺ID
     *
     * @apiSuccess {Long} id 门店ID
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccess {Long} version 版本
     * @apiSuccess {String} name 名称
     * @apiSuccess {String} type 类型 STORE("实体店"), SHOP("网店")
     * @apiSuccess {String} address 地址
     * @apiSuccess {String} third 网店(网址)
     * @apiSuccess {String} phone 电话(手机/座机)
     * @apiSuccess {Long} locationId 地区ID
     * @apiSuccess {Long} locationStr 地区文本
     * @apiSuccess {String} status 状态 ENABLE("启用"), DISABLE("停用")
     * @apiSuccess {String} number 门店编号(生成规则 001 - 999)
     * @apiSuccess {String} exchange 是否支持现有所有产品在此店兑换或自提(是:YES,否:NO)
     * @apiSuccess {String} introduction 介绍
     * @apiSuccess {Long} merchantId 商家 id
     * @apiSuccess {Long} mallId 平台ID
     *
     * @apiSuccessExample {json} Success-Response:
     * {
     *  "code": "1",
     *  "desc": "成功",
     *  "data": {
     *              "id": 1,
     *              "dateCreated": "2016-05-05 18:16:12",
     *              "lastUpdated": "2016-11-18 15:51:48",
     *              "version": 0,
     *              "name": "甜店",
     *              "type": "STORE",
     *              "address": "越秀区",
     *              "phone": "18216280038,,",
     *              "locationId": 440104,
     *              "locationStr": "广东省",
     *              "status": "ENABLE",
     *              "number": "001",
     *              "exchange": "YES",
     *              "introduction": "卖点超好",
     *              "merchantId": 2
     *          }
     *  }
     *
     */
    @RequestMapping(value=Routes.MERCHANT_STORE,method = RequestMethod.GET)
    @ResponseBody
    public JsonResult findStore(Long storeId, HttpServletRequest request){
        RestDoing doing = jr ->{
            if (storeId == null){
                jr.remind("storeId is null",log);
                return;
            }
            MerchantStore merchantStore = merchantStoreRepository.findByIdAndStatusAndIsDelete(storeId,MerchantStoreStatus.ENABLE,Whether.NO);
            if (merchantStore == null){
                jr.errorParam("店铺已不存在或停用",log);
                return;
            }
            jr.setData(merchantStore);
        };
        return doing.go(request,log);
    }
}
